<?php
/**
 *  The Parser's __dict__ contains the parsed values:
 *  NOTE:    A parsed value is actually a Model field with a preset value
 *
 */
abstract class Yz_Form_Parser_Abstract
    extends Yz_Class
    implements Yz_Form_Parser_Interface
{


    protected $errors = array();


    /**
     *  @var Yz_Form_Interface
     */
    protected $form;

    /****************************
     *      Public methods      *
     ****************************/


    public function __construct(Yz_Form_Interface $form)
    {
        $this->form = $form;
    }


    /**
     *  @param form
     *  @param ArrayAccess values to be parsed
     *  @return array
     */
    public function parse(Yz_Hash $input)
    {
        debug();
        $this->errors = array();
        $values =& $this->__dict__;
        foreach ($this->form as $element) {

            // whether to ignore element
            if (! $element->isParseable())
                continue;
            // TODO callbacks
            try {
                $values[$element->getName()] = $element->parse($input);
            } catch (Yz_Form_Element_Error $ex) {
                // element validation failure
                $this->errors[] = $ex;
            }
        }
        if ($this->errors)
            throw Yz_Form_Error_ValidationError::_new_();
        return $this;
    }

    /**
     *  these may be element-related as well as global
    final public function getErrors()
    {
        return $this->errors;
    }
     */



}
